This page last changed on Feb 14, 2008 by sfentress.

There are 2 layers of services in OTrunk. The object/model layer and controller/view layer. This page deals with the controller/view layer for information on the object/model layer look at this page: OTrunk Services

Accessing Services

If your view is a subclass of AbstractOTView then services can be accessed by calling the method:
getViewService(Class serviceClass);
The serviceClass should be the class or interface of the service you are looking for.

If you view doesn't subclass AbstractOTView, then it needs to implement the plumbing so it can look up services. This is done by:
implementing OTViewContextAware - this requires your class to have a setViewContext method.
then when you want a service you call getViewSerivce on the passed in OTViewContext.

Adding Services

There are 2 ways to add view services.

  1. using the OTBundle mechanism
  2. using the OTViewContext object

Create a new bundle or modify an existing bundle. See OTrunk Services for information about bundles. Then in the initializeBundle method of your bundle

get the viewFactory from the serviceContext and add your new view service. For example:

From OTScriptEngineBundle
public void initializeBundle(OTServiceContext serviceContext)
{
  OTViewFactory viewFactory = 
     (OTViewFactory) serviceContext.getService(OTViewFactory.class);
    	
  viewFactory.addViewService(scriptManager);
}

Add the service to the view context.

If your view gets its own OTViewContext and uses the addViewService method then that service will be available to your view and all of its siblings. The service will not be availabe to any parents of this view.
There are 3 cases where this might be used:

  1. a child view wants sibling views to have access to a service it provides. In this case, the child will get its view context as described in "Accessing Services" above. Then call the addViewService method.
  2. a parent view wants to provide a service to its children. In this case the parent view will have created a OTViewFactory inorder to create its child views. The viewContext that will be passed to these children can be accessed using the getViewContext on the otViewFactory instance. Then the addViewService can used to add the service to that.
  3. modifying the top level startup objects: OTViewer, OTViewerHelper, and OTReportViewer In this case, you going to add your new service to the top level viewFactory. Here is the snippet from OTViewer where these services are being setup:
    OTViewContext factoryContext = otViewFactory.getViewContext();
    factoryContext.addViewService(OTrunk.class, otrunk);
    factoryContext.addViewService(OTFrameManager.class, frameManager);
    factoryContext.addViewService(OTJComponentServiceFactory.class, new OTJComponentServiceFactoryImpl());
    

Current View Services

OTrunk - The OTrunk object itself is added as a view service
OTFrameManager - is added so views can make new frames
OTJComponentServiceFactory - is added so views get JComponents from other views. There is some setup needed when accessing the JComponent from another view and this service takes care of that for you.
OTScriptManager - this allows a view to execute scripts.
OTControllerServiceFactory - this allows a view to use the OTController system. This system helps connect POJOs to their OTObject through controllers.
OTSharingManager - this allows objects to be shared across other obejcts

Nested OTViewFactories

Multiple OTViewFactories are created. This is used a few ways.

  1. Each view that has children views creates a nested OTViewFactory to create those children views. This allows specific services to be added to just those views, and it allows those views to look up each other.
  2. It is also used by the OTReportViewer. It allows it to show an aggregate view of the object in one place and single user view in another.

As far as services are concerned, first the service is searched for in the current view factory and if it has a parent then the service is looked for in the parent, and if it has a parent it is looked for there.

Document generated by Confluence on Jan 27, 2014 16:52